package middleware

import (
	"saas-app/app/dao"
	"saas-app/library/response"

	"github.com/gogf/gf/net/ghttp"
)

func ClassAuth(r *ghttp.Request) {

	class_id := r.GetQueryUint("class_id")
	school_id := r.GetCtxVar("school_id").Int()
	campus_id := r.GetCtxVar("campus_id").Int()

	if record, err := dao.Classes.Where("id = ?", class_id).Where("school_id = ?", school_id).Where("campus_id = ?", campus_id).FindOne(); err != nil {
		response.JsonExit(r, 1, err.Error())
	} else {
		if record == nil {
			response.JsonExit(r, 110, "无权限")
		}
	}

	r.Middleware.Next()
}
